<template>
    <a-drawer popup-container="#wrap" width="500px" :visible="show" :ok-loading="form.loading" @ok="submit"
        @cancel="show = false" unmountOnClose>
        <template #title>
            {{ $t('components.create.60zemc8cafg0') }}
        </template>
        <div class="table-info">
            <a-form ref="formRef" :model="form.data" @submit="submit" layout="vertical">
                <a-form-item field="uavId" label="UASID"
                    :rules="[{ type: 'array', required: true, message: $t('components.create.60zemc8ccbw0') }]">
                    <a-input v-model="form.data.uavId" :placeholder="$t('components.create.60zemc8ccbw0')" />
                </a-form-item>
                <a-form-item field="uavNum" :label="$t('components.create.60zecmbl56w2')"
                    :rules="[{ type: 'array', required: true, message: $t('components.create.60zemc8ccbw0') }]">
                    <a-input v-model="form.data.uavNum" :placeholder="$t('components.create.60zemc8ccbw0')" />
                </a-form-item>
                <a-form-item field="customerName" :label="$t('components.create.61zemc8cb784')"
                    :rules="[{ type: 'array', required: true, message: $t('components.create.60zemc8ccbw0') }]">
                    <a-input v-model="form.data.customerName" :placeholder="$t('components.create.60zemc8ccbw0')" />
                </a-form-item>
                <!-- <a-form-item field="mobile" :label="$t('components.create.60zemc8cc180')" :rules="[{ message: $t('components.create.60zemc8cc3w0') },{match:/^1[3456789]\d{9}$/,message:$t('components.create.60zemc8cc3w1')}]">
                    <a-input v-model="form.data.mobile" :placeholder="$t('components.create.60zemc8cc3w0')"/>
                </a-form-item> -->
            </a-form>
        </div>
    </a-drawer>
</template>

<script lang='ts' setup>
import { defineModel } from 'vue'
import { apiReportCreate } from '@/api/visual'
const local = useLocal()
const show = defineModel('show', { default: false })
const formRef = ref()
const emit = defineEmits(['refresh'])
const form = reactive({
    data: {
        uavId: '',
        uavNum: '',
        suffix: '',
        color:'',
        customerName:'',
        mobile: 0,
        uid: local.usermsg.id == 3 ? 0 : local.usermsg.id
    },
    loading: false,
})
const submit = async () => {
    const validate = await formRef.value?.validate()
    if (validate) return;
    form.loading = true
    const { code } = await apiReportCreate({
        ...form.data,
    })
    form.loading = false
    if (code != 200) return;
    emit('refresh')
    formRef.value?.resetFields()
    show.value = false
}
</script>

<style scoped></style>